class Solution(object):
    def maxEnvelopes(self, envelopes):
        """
        :type envelopes: List[List[int]]
        :rtype: int
        """

        n = len(envelopes)
        if n==0:
            return 0
        envelopes = sorted(envelopes)
        f = [0] * (n)
        res=  0
        for i in range(n):
            f[i] = 1
            for j in range(i):
                if envelopes[i][0]>envelopes[j][0] and envelopes[i][1] >envelopes[j][1]:
                    f[i] = max(f[i],f[j]+1)
            res = max(res,f[i])
        return res


a = [[1,1],[2,3],[2,2]]
s=Solution()
m=s.maxEnvelopes(a)
print(m)